<template>
  <div>
    <common-login :checks="true" @toLogin="login" @getCode="getCode" ref="login"/>
  </div>
</template>

<script>
import commonLogin from '@/components/commonLogin'
import api from '@/api'
export default {
  name: 'login',
  data () {
    return {}
  },
  methods: {
    login (data) {
      console.log(data)
      let params = {
        ver_number: data.code,
        ver_phone: data.phone
      }
      api.agencyLogin({
        params,
        callback: res => {
          if (res.data.error_code === 0) {
            sessionStorage.setItem('user', JSON.stringify(res.data.data))
            this.$toast.success({
              message: res.data.message,
              duration: 1000,
              forbidClick: true,
              onClose: () => {
                localStorage.setItem('token', res.data.data.token)
                if (res.data.data.perfect === 2) {
                  // 当perfect的值为2时，跳转到用户完善个人信息页面
                  this.$router.push({path: '/agencyImpInfo', query: {id: res.data.data.id}})
                } else {
                  this.$router.push('/my/index')
                }
              }
            })
          } else {
            this.$toast(res.data.message)
            this.$refs['login'].setLoading()
          }
        }
      })
    },
    // login (params) {
    //   console.log(params)
    //   this.$router.push('/agencyImpInfo')
    // },
    getCode (phone) {
      api.agencySendMsg({
        params: {phone, type: '1'},
        callback: res => {
          this.$toast(res.data.message)
          this.$refs['login'].setCodeStatus(res.data.error_code === 0)
          console.log(res)
        }
      })
    }
  },
  components: {
    commonLogin
  },
  created () {
  }
}
</script>

<style scoped>
  .container{
    padding: 0 15px;
  }
</style>
